import router from '@system.router';

export default {
    data: {
        items: [
        ],
        yuan: 0,
        fen: ".00",
        sum: 0
    },
    onInit() {
        this.fetch();
    },
    go(path) {
        router.push({ uri: path });
    },
    fetch() {
        for (let i = 0; i < 5; ++i) {
            this.items.push(
                {
                    shop: "速浪旗舰店",
                    name: "速浪夏威夷男士短袖衬衫",
                    color: "薄荷之夏；XL",
                    yuan: 169,
                    fen: "",
                    price: 169,
                    amount: 1,
                    pic: "common/images/detail/picture1.png"
                }
            );
        }
    },
    selectItem(i, checkbox) {
        if (checkbox.checked) {
            this.sum += this.items[i].price;
        } else {
            this.sum -= this.items[i].price;
        }
        this.parsePrice();
    },
    parsePrice() {
        this.yuan = Math.floor(this.sum);
        this.fen = "" + (this.sum - this.yuan);
        this.fen = this.fen.substr(1, 3);
    }
}
